<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_取消单管理</title>
	<script type="text/javascript">
	
        $(function() {
		    $("#queryForm").validate(); 
		    $("#inputForm").validate();
			$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
       });
	  
	  //级联商家仓库
	  function ajaxAreaGroup(item) {
		    $("#_warehouseCode").html("<option value=''></option>");
			customerCode=item.value;
			if(customerCode==''){
				return false;
			}
			$.ajax({
				type : 'post',
				url : '${ctx}/areaGroup/ajaxAreaGroup',
				data : 'customerCode=' + customerCode,
				dataType : 'json',
				success : function(data) {
				  var tempString="<option value=''></option>";
					if (data.status == "1") {
						$.each(data.content,function(i){
						    tempString+="<option value="+data.content[i].groupCode+">"+data.content[i].groupName;
						});
					}else if (data.status == "2") {
						$.each(data.content.restAreaGroupDtos,function(i){
						    tempString+="<option value="+data.content.restAreaGroupDtos[i].areagroupCode+">"+data.content.restAreaGroupDtos[i].areagroupName;
						});
					} else {
						alert(data.content);
					}
	                      $("#_warehouseCode").html(tempString);
	                      $("#_warehouseCode").trigger("chosen:updated");
				},
				error : function() {
					alert("获取信息错误！");
				}
			});
		}
		
		//取消单重发
		function recall(orderno){
		
		    var btn=$("#btn_"+orderno);
		    btn.attr("disabled", true);
		    
		    $.ajax({
			type:'post',
			url:'${ctx}/cancelOrder/ajaxRecall',
			data:{
				orderno:orderno
			},
			dataType:'json',
			success:function(data) {
			    var msg=data.msg;
			    
			    if(msg=='success'){
			       alert("重发操作成功。");
			       btn.remove();
			       $("#status_"+orderno).html("<font color=blue>已重发</font>");
			    }else if(msg=='noExist'){
			       alert("不存在此单号");
			       btn.attr("disabled", false);
			    }else if(msg=='recalled'){
			       alert("已重发，不能重复重发！");
			       btn.attr("disabled", false);
			    }else{
			       alert("网络繁忙，请稍后重试...");
			       btn.attr("disabled", false);
			    }
			    
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled", false);
			}
	   });
	   
	}
	
	//拦截标识
	function cancelFlag(orderno,flag){
		
		var btn_pass=$("#btn_pass_"+orderno);
		var btn_stop=$("#btn_stop_"+orderno);
		btn_pass.attr("disabled", true);
		btn_stop.attr("disabled", true);
		
	    $.ajax({
			type:'post',
			url:'${ctx}/cancelOrder/ajaxCancelFlag',
			data:{
				orderno:orderno,
				flag:flag
			},
			dataType:'json',
			success:function(data) {
			
			    var msg=data.msg;
			    
			    if(msg=='success'){
			       alert("标识成功!");
			       
			       btn_pass.remove();
			       btn_stop.remove();
			       
			       if(flag=='stop'){
			          $("#cancelStatus_"+orderno).html("<font color=green>拦截成功</font>");
			       }else if(flag=='pass'){
			          $("#cancelStatus_"+orderno).html("<font color=red>拦截失败</font>");
			       }
			       
			    }else if(msg=='error'){
			       alert("标识失败");
			       btn_pass.attr("disabled", false);
			       btn_stop.attr("disabled", false);
			    }else{
			       alert("网络繁忙，请稍后重试...");
			       btn_pass.attr("disabled", false);
			       btn_stop.attr("disabled", false);
			    }
			    
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled", false);
			}
	   });
	   
	}
	  
    </script>
</head>

<body>
	<div style="height: 10px;"></div>
	
	<form class="form-search" id="queryForm" action="${ctx}/cancelOrder/queryCancelOrder" method="post">
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="1" bgcolor="#8EB4CB">条件查询</th>
		</thead>
		
		<tr >
		   <td>
			    <label style="margin-left: 10px;">商家名称:</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="input-medium required" onchange="ajaxAreaGroup(this);">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
				
				<label style="margin-left: 10px;">作业仓库</label>
				 <select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="input-medium">
					<option value=""></option>
					<c:forEach items="${warehouseList}" var="w" >
					   <option value="${w.groupCode}" 
					   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
					   >${w.groupName}</option>
				   </c:forEach>
				</select>
				
				<label style="margin-left: 10px;" >订单号/快递单号:</label>
				<input type="text" id="_allOrderno" name="_allOrderno"  class="input-medium" value="${param._allOrderno}"/>
				
	    </td></tr>
	    
	    <tr >
		   <td>
				<label>&nbsp;&nbsp;&nbsp;登记时间:</label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="input-small" value="${param._fromDate}" > 
			 	<label>至</label> 
			 	<input type="text" name="_toDate" id="_toDate" class="input-small" value="${param._toDate}"> 
			 	
			    <button type="submit" class="btn btn-info" style="margin-left: 10px;">搜索</button>
			    <a href="${ctx}/cancelOrder/v2_toCancelOrderPage" role="button"  class="btn btn-primary" >登记取消单</a>

	    </td></tr>
	</table>
	 </form>
	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
	     <thead>
			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#8EB4CB">查询结果</th>
		</thead>
		<thead><tr>
			    <th>序号</th>
			    <th>商家名称</th>
			    <th>能容订单号</th>
<!-- 			    <th style="width: 150px;">商家订单号</th> -->
			    <th>快递单号</th>
			    <th>作业仓库</th>
			    <th>登记人</th>
			    <th>登记时间</th>
			    <th>异常类型</th>
<!-- 			    <th>重发操作</th> -->
<!-- 			    <th>拦截操作</th> -->
			</tr></thead>
		<tbody>
		<c:if test="${page ne null}">
		<c:forEach items="${page.content}" var="o" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${o.customerCode}</td>
			   <td><a href="${ctx}/orderMsg/v2_orderMsgDetail/${o.orderno}" title="查看订单信息">${o.orderno}</td>
			   <td>${o.expressNo}</td>
			   <td>
			     <c:if test='${not empty o.warehouse}'>
			         ${o.warehouse.groupName}
			     </c:if>
			   </td>
			   <td>${o.creater.realname}</td>
			   <td>${o.createTime}</td>
			   
			   <td>
			     <c:if test='${o.exceptionType eq "cancel"}'><font color=red>取消单</font></c:if>
			   </td>
			   
<!-- 			   <td id="status_${o.orderno}"> -->
<!-- 			      <c:if test='${o.recallFlag eq "recall"}'>已重发</c:if> -->
<!-- 			      <c:if test='${o.recallFlag eq "unrecall"}'> -->
<!-- 			         <button id="btn_${o.orderno}"  class="btn btn-info" onclick="recall('${o.orderno}');">重发</button> -->
<!-- 			      </c:if> -->
<!-- 			   </td> -->
<!-- 			   <td id="cancelStatus_${o.orderno}"> -->
<!-- 			     <c:if test="${o.cancelStatus eq 'stop'}"><font color=green>拦截成功</font></c:if> -->
<!-- 			     <c:if test="${o.cancelStatus eq 'pass'}"><font color=red>拦截失败</font></c:if> -->
<!-- 			     <c:if test="${o.cancelStatus eq 'regist' }"> -->
<!-- 				        <button id="btn_stop_${o.orderno}"  class="btn btn-success" onclick="cancelFlag('${o.orderno}','stop');">已拦截</button> -->
<!-- 				        <button id="btn_pass_${o.orderno}"  class="btn btn-danger" onclick="cancelFlag('${o.orderno}','pass');">未拦截</button> -->
<!-- 				 </c:if> -->
<!-- 			   </td> -->
			   
			</tr>
		</c:forEach>
		</c:if>
		</tbody>
	</table>
	
	
	<c:if test="${page ne  null}">
	<tags:pagination page="${page}" paginationSize="5"/>
	</c:if>
	
</body>
</html>
